package com.xthh.esl;



/**
 * @author : wuyajiang
 * @version : 0.0.1
 * @Date : 2024/10/22 19:21
 * @E-Mail : wuyajiang@fmsh.com.cn
 */
public class SE0398N {
    private static final int H_RES = 768;
    private static final int V_RES = 552;

    public static void swap_pic_n02(byte[] dest, byte[] src)
    {

        int hResByte = (H_RES % 8) > 0 ? (H_RES / 8 + 1) : (H_RES / 8);

        // 第一部分交换
        for (int i = 0; i < V_RES / 2; i++) {
            int k = hResByte * (V_RES / 2 - 1 - i);
            for (int j = 0; j < hResByte; j++) {
                dest[i * hResByte + j] = src[k + j];
            }
        }

        // 第二部分交换
        for (int i = V_RES / 2; i < V_RES; i++) {
            int k = hResByte * i;
            for (int j = 0; j < hResByte; j++) {
                dest[i * hResByte + j] = src[k + j];
            }
        }

    }


    /**
     *
     *  d      转换后的结果
     * @param s     源图片数据
     */
    public static byte[] swapPic4(byte[] d, byte[] s)
    {
        int hResBytes = (H_RES % 4) != 0 ? (H_RES / 4 + 1) : (H_RES / 4);

        for (int i = 138; i <= 275; i++) {
            int k = hResBytes * (V_RES - 1 - 2 * i);
            for (int j = 0; j < hResBytes; j++) {
                d[k + j] = s[i * hResBytes + j];
            }
        }

        for (int i = 276; i <= 413; i++) {
            int k = hResBytes * (2 * (i - V_RES / 2));
            for (int j = 0; j < hResBytes; j++) {
                d[k + j] = s[i * hResBytes + j];
            }
        }

        for(int i=0; i<=137; i++)
        {
            int k = hResBytes*(V_RES-1-2*i-276);
            for(int j=0; j<hResBytes; j++)
            {
                d[k+j] = s[i*hResBytes+j];
            }

        }
        for(int i=414; i<=551; i++)
        {
            int k = hResBytes*(2*(i-V_RES/2)-276);
            for(int j=0; j<hResBytes; j++)
            {
                d[k+j] = s[i*hResBytes+j];
            }

        }
        return d;
    }

    /**
     *
     *  d      转换后的结果
     * @param s     源图片数据
     */
    public static byte[] swap_pic_n01(byte[] d, byte[] s)
    {
        int  h_res_byte = (H_RES%4!=0)? (H_RES/4+1) : (H_RES/4);
        byte[] d1 = new byte[768/4*552/2];
        byte[] d2 = new byte[768/4*552/2];

        for(int i=138; i<=275; i++)
        {
            int k = h_res_byte*(V_RES-1-2*i);
            for(int j=0; j<h_res_byte; j++)
            {
                d1[k+j] = s[i*h_res_byte+j];
            }

        }
        for(int i=276; i<=413; i++)
        {
            int k = h_res_byte*(2*(i-V_RES/2));
            for(int j=0; j<h_res_byte; j++)
            {
                d1[k+j] = s[i*h_res_byte+j];
            }

        }


        for(int i=0; i<=137; i++)
        {
            int k = h_res_byte*(V_RES-1-2*i-276);
            for(int j=0; j<h_res_byte; j++)
            {
                d2[k+j] = s[i*h_res_byte+j];
            }

        }
        for(int i=414; i<=551; i++)
        {
            int k = h_res_byte*(2*(i-V_RES/2)-276);
            for(int j=0; j<h_res_byte; j++)
            {
                d2[k+j] = s[i*h_res_byte+j];
            }

        }


//        memcpy(&d[0], d1, 768/4*552/2);
//        memcpy(&d[h_res_byte*V_RES/2], d2, 768/4*552/2);

        int copyBytes = 768 / 4 * 552 / 2;
        System.arraycopy(d1, 0, d, 0, copyBytes);

        int startIndex = h_res_byte * V_RES / 2;
        System.arraycopy(d2, 0, d, startIndex, copyBytes);

        return d;
    }
}
